#! /bin/bash

#自定义欢迎语
#modify the  file from /etc/update-motd.d  for identification



#####  header
# Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-37-generic x86_64)

##### 10-help-text
#  * Documentation:  https://help.ubuntu.com
#  * Management:     https://landscape.canonical.com
#  * Support:        https://ubuntu.com/advantage

##### 90-updates-available
# Expanded Security Maintenance for Applications is not enabled.

# 101 updates can be applied immediately.
# 75 of these updates are standard security updates.
# To see these additional updates run: apt list --upgradable

# Enable ESM Apps to receive additional future security updates.
# See https://ubuntu.com/esm or run: sudo pro status


##### 还没找到
#91
# The programs included with the Ubuntu system are free software;
# the exact distribution terms for each program are described in the
# individual files in /usr/share/doc/*/copyright.
#92
# Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
# applicable law.

################################################################
# 备份原件
dt=`date +'%Y%m%d%H%M%S'`
sudo mkdir /var/backup-$dt
sudo cp -r /etc/update-motd.d ~/backup


################################################################
# 修改 00-header

echo -e "#!/bin/sh" >00-header
echo -e "printf \"  ██████████████████████████████████ \\\n\"" >>00-header
echo -e "printf \" ███████████ █████████████ ██████████     █                            ▀\\\n\"">>00-header
echo -e "printf \" ██ ██ ██ ██    ███   ████ ███ ▄▄ ███  ████  █  █   ██   ██    ██ ██   █  █▀▀▄\\\n\"">>00-header
echo -e "printf \" ██ ██ ██ ██ ██ ██ ███ ███ ██      ██ █   █  █▄▄█  █  █ █  █  █  █  █  █ █\\\n\"">>00-header
echo -e "printf \" ███  █  ███ ██ ███   █ ██ ███ ▀▀▀███  ███    ▀▀█  █  █  ██ █ █  █  █  █  █▄▄▀\\\n\"">>00-header
echo -e "printf \"  ██████████████████████████████████          ▄▄█\\\n\"">>00-header
echo -e "printf \"\\\n\"">>00-header
#echo -e "printf \"Welcome to %s (%s %s %s)\\\n\" \"\$DISTRIB_DESCRIPTION\" \"\$(uname -o)\" \"\$(uname -r)\" \"\$(uname -m)\"">>00-header

sudo cp 00-header /etc/update-motd.d/00-header

################################################################
#修改 10-help-text  帮助文档，主要展示logo，公司信息
echo -e "#!/bin/sh" >10-help-text
echo -e "printf \"  Welcome to visit :  http://whaledynamic.com\\\n\"">>10-help-text
echo -e "printf \"  欢迎访问中文站点 :  http://cn.whaledynamic.com\\\n\"">>10-help-text

sudo cp 10-help-text /etc/update-motd.d/10-help-text

################################################################
# 修改 90-updates-available

echo -e "#!/bin/sh" >90-updates-available

echo -e "[ -r /etc/lsb-release ] && . /etc/lsb-release" >>90-updates-available
echo -e "if [ -z \"\$DISTRIB_DESCRIPTION\" ] && [ -x /usr/bin/lsb_release ]; then" >>90-updates-available
echo -e "	DISTRIB_DESCRIPTION=\$(lsb_release -s -d)" >>90-updates-available
echo -e "fi">>90-updates-available

echo -e "printf \"\\\n\"">>90-updates-available
echo -e "printf \"System       : %s\\\n\" \"\$DISTRIB_DESCRIPTION\"">>90-updates-available
echo -e "printf \"Kernel       : %s\\\n\" \"\$(uname -r)\"">>90-updates-available
echo -e "printf \"Architecture : %s\\\n\" \"\$(uname -m)\"">>90-updates-available
echo -e "if [ nvidia-smi>/dev/null ] ; then">>90-updates-available
echo -e "   printf \"GPU          : %s-%s°C-%s\\\n\" \"\$(nvidia-smi --query-gpu=name --format=csv|awk 'NR==2')\" \"\$(nvidia-smi --query-gpu=temperature.gpu --format=csv|awk 'NR==2')\" \"\$(nvidia-smi --query-gpu=fan.speed --format=csv|awk 'NR==2')\" ;">>90-updates-available
echo -e "else ">>90-updates-available
echo -e "   printf \"GPU          : No Access\\\n\";">>90-updates-available
echo -e "fi">>90-updates-available
echo -e "printf \"Network      : %s\\\n\" \"\$(ip addr |grep /24|awk 'BEGIN{ORS=\" \"}{print \$2}END{print \"\\\n\"}')\"">>90-updates-available
# 显示器需要额外权限 echo -e "printf \"Monitor      : %s\\\n\" \"\$(


sudo apt install -y lm-sensors 1>/dev/null 2>&1
echo -e "printf \"CPU-Tem      : %s\\\n\" \"\$(sensors |grep -i 'core '|awk 'BEGIN{ORS= \" / \";print \"\"}{print \$2 OFS \$3}')\"">>90-updates-available

# cpu frequency
echo -e "printf \"CPU-Freq     : %s\\\n\" \"\$(cat /proc/cpuinfo |grep -i 'cpu mhz'|awk 'BEGIN{ORS=\" / \";print \"\"}{print \$4}')\"">>90-updates-available

echo -e "printf \"\\\n\"" >>90-updates-available
sudo cp 90-updates-available /etc/update-motd.d/90-updates-available
sudo rm -f /etc/update-motd.d/91-release-upgrade /etc/update-motd.d/91-contract-ua-esm-status /etc/update-motd.d/92-unattended-upgrades 1>/dev/null 2>&1